require 'httpclient'

module NewsHelper

  #综合新闻的全部栏目
  zonghe = Category.where(:cataname => '综合新闻').first
  ZHXW_CATEGORY = zonghe.id
  ZHXW_CATEGORIES = ([zonghe.id] +zonghe.children.collect(&:id))

  #招生就业的全部栏目
  zhaosheng = Category.where(:cataname => '招生就业').first
  ZSJY_CATEGORY = zhaosheng.id
  ZSJY_CATEGORIES = ([zhaosheng.id] +zhaosheng.children.collect(&:id))

  #合作交流的全部栏目
  hzjl = Category.where(:cataname => '合作交流').first
  HZJL_CATEGORY = hzjl.id
  HZJL_CATEGORIES = ([hzjl.id] +hzjl.children.collect(&:id))

  #深度报道的全部栏目
  sdbd = Category.where(:cataname => '深度报道').first
  SDBD_CATEGORY = sdbd.id
  SDBD_CATEGORIES = [sdbd.id]

  #图说华理的全部栏目
  tshl = Category.where(:cataname => '图说华理').first
  TSHL_CATEGORY = [tshl.id]

  #媒体华理的全部栏目
  mthl = Category.where(:cataname => '媒体华理').first
  MTHL_CATEGORY = [mthl.id]

  #一级栏目
  CATEGORY_HASH_ARRAY = {
    zonghe.id.to_s  => ([zonghe.id] +zonghe.children.collect(&:id)),
    zhaosheng.id.to_s  => ([zhaosheng.id] +zhaosheng.children.collect(&:id)),
    hzjl.id.to_s  => ([hzjl.id] +hzjl.children.collect(&:id)),
    sdbd.id.to_s => [sdbd.id],
    tshl.id.to_s => [tshl.id],
    mthl => [mthl.id]
  }
  
  def breadnumb category
    id = category.id.to_i
    breadnumb_str = ""
    if ZHXW_CATEGORIES.include? id and ZHXW_CATEGORY != id
      breadnumb_str = '<a href="/news?category_id=7"> > 综合新闻</a>'
    elsif ZSJY_CATEGORIES.include? id and ZSJY_CATEGORY != id
      breadnumb_str = '<a href="/news?category_id=63"> > 招生就业</a>'
    elsif HZJL_CATEGORIES.include? id and HZJL_CATEGORY != id
      breadnumb_str = '<a href="/news?category_id=38"> > 合作交流</a>'
    elsif SDBD_CATEGORIES.include? id and SDBD_CATEGORY != id
      breadnumb_str = '<a href="/news?category_id=60"> > 深度报道</a>'
    end
    breadnumb_str
  end
  
  
  def writer
    client = HTTPClient.new
    client.get_content('http://www.baidu.com') do |chunk|
        puts chunk
     end
  end
    

end